package filecloud;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;

public class CloudFile extends File {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long cachedFreeSpace;

	public CloudFile(File parent, String child) {
		super(parent, child);
		refreshCachedFreeSpace();
	}

	public CloudFile(String parent, String child) {
		super(parent, child);
		refreshCachedFreeSpace();
	}

	public CloudFile(String pathname) {
		super(pathname);
		refreshCachedFreeSpace();
	}

	public CloudFile(URI uri) {
		super(uri);
		refreshCachedFreeSpace();
	}

	@Override
	public boolean canExecute() {
		return super.canExecute();
	}

	@Override
	public boolean canRead() {
		return super.canRead();
	}

	@Override
	public boolean canWrite() {
		return super.canWrite();
	}

	@Override
	public int compareTo(File pathname) {
		return super.compareTo(pathname);
	}

	@Override
	public boolean createNewFile() throws IOException {
		return super.createNewFile();
	}

	@Override
	public boolean delete() {
		return super.delete();
	}

	@Override
	public void deleteOnExit() {
		super.deleteOnExit();
	}

	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

	@Override
	public boolean exists() {
		return super.exists();
	}

	@Override
	public File getAbsoluteFile() {
		return super.getAbsoluteFile();
	}

	@Override
	public String getAbsolutePath() {
		return super.getAbsolutePath();
	}

	@Override
	public File getCanonicalFile() throws IOException {
		return super.getCanonicalFile();
	}

	@Override
	public String getCanonicalPath() throws IOException {
		return super.getCanonicalPath();
	}

	@Override
	public long getFreeSpace() {
		
		return super.getFreeSpace();
	}

	@Override
	public String getName() {
		
		return super.getName();
	}

	@Override
	public String getParent() {
		
		return super.getParent();
	}

	@Override
	public File getParentFile() {
		
		return super.getParentFile();
	}

	@Override
	public String getPath() {
		
		return super.getPath();
	}

	@Override
	public long getTotalSpace() {
		
		return super.getTotalSpace();
	}

	@Override
	public long getUsableSpace() {
		
		return super.getUsableSpace();
	}

	@Override
	public int hashCode() {
		
		return super.hashCode();
	}

	@Override
	public boolean isAbsolute() {
		
		return super.isAbsolute();
	}

	@Override
	public boolean isDirectory() {
		
		return super.isDirectory();
	}

	@Override
	public boolean isFile() {
		
		return super.isFile();
	}

	@Override
	public boolean isHidden() {
		
		return super.isHidden();
	}

	@Override
	public long lastModified() {
		
		return super.lastModified();
	}

	@Override
	public long length() {
		
		return super.length();
	}

	@Override
	public String[] list() {
		
		return super.list();
	}

	@Override
	public String[] list(FilenameFilter filter) {
		
		return super.list(filter);
	}

	@Override
	public File[] listFiles() {
		
		return super.listFiles();
	}

	@Override
	public File[] listFiles(FileFilter filter) {
		
		return super.listFiles(filter);
	}

	@Override
	public File[] listFiles(FilenameFilter filter) {
		
		return super.listFiles(filter);
	}

	@Override
	public boolean mkdir() {
		
		return super.mkdir();
	}

	@Override
	public boolean mkdirs() {
		
		return super.mkdirs();
	}

	@Override
	public boolean renameTo(File dest) {
		
		return super.renameTo(dest);
	}

	@Override
	public boolean setExecutable(boolean executable, boolean ownerOnly) {
		
		return super.setExecutable(executable, ownerOnly);
	}

	@Override
	public boolean setExecutable(boolean executable) {
		
		return super.setExecutable(executable);
	}

	@Override
	public boolean setLastModified(long time) {
		
		return super.setLastModified(time);
	}

	@Override
	public boolean setReadable(boolean readable, boolean ownerOnly) {
		
		return super.setReadable(readable, ownerOnly);
	}

	@Override
	public boolean setReadable(boolean readable) {
		
		return super.setReadable(readable);
	}

	@Override
	public boolean setReadOnly() {
		
		return super.setReadOnly();
	}

	@Override
	public boolean setWritable(boolean writable, boolean ownerOnly) {
		
		return super.setWritable(writable, ownerOnly);
	}

	@Override
	public boolean setWritable(boolean writable) {
		
		return super.setWritable(writable);
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer(10);
		sb.append(getPath());
		sb.append(" - ");
		sb.append(getFormattedCachedFreeSpace());
		
		return sb.toString();
	}

	@Override
	public URI toURI() {
		
		return super.toURI();
	}

	public long getCachedFreeSpace() {
		return cachedFreeSpace;
	}
	
	public void refreshCachedFreeSpace(){
		cachedFreeSpace = getFreeSpace();
	}
	
	public String getFormattedCachedFreeSpace(){
		StringBuffer sb = new StringBuffer(5);
		double freebyte = getCachedFreeSpace();
	    double temp = Math.pow(1024,3);
	    double freegb = (double)freebyte/temp;
	    BigDecimal bd = new BigDecimal(freegb).setScale(2, RoundingMode.HALF_EVEN);
	    sb.append(bd);
	    sb.append("GB");
	    
	    return sb.toString();
	}
}
